<template>
  <el-container class="main_con">
    <div class="list_con">
      <el-table @selection-change="SelectHadnle" :data="list" element-loading-text="" fit highlight-current-row>
        <!-- <el-table-column type="selection" width="55" align="center"></el-table-column> -->
        <el-table-column prop="name" label="名称"></el-table-column>
        <el-table-column prop="img" label="图标">
          <template slot-scope="scope">
            <img style="width: 50px;height: 50px;" :src="scope.row.img" />
          </template>
        </el-table-column>
        <el-table-column prop="new_version" label="当前版本"></el-table-column>
        <!-- <el-table-column prop="price" label="售价"></el-table-column> -->
        <el-table-column prop="status" label="插件状态">
          <template slot-scope="scope">
            <span>{{ scope.row | getstatus }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="create_time" label="创建时间"></el-table-column> -->
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button v-if="!scope.row.is_active" type="text" @click="beforeactive(scope.row.id)">激活</el-button>
            <el-button v-if="scope.row.is_active && scope.row.is_support_install && !scope.row.is_install" type="text" @click="install(scope.row.id)">安装</el-button>
            <el-button v-if="scope.row.is_active && scope.row.is_support_install && scope.row.is_install" type="text" @click="uninstall(scope.row.id)">卸载</el-button>
            <!-- <el-button type="text" @click="EditHandle(scope.row)">编辑</el-button> -->
            <!-- <el-button type="text" @click="EnableHandle(scope.row)">{{ scope.row.status == '1' ? '禁用' : '启用' }}</el-button> -->
            <!-- <el-button type="text" @click="handleClose(scope.row.id)">删除</el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <!--      <div class="table_footer">
        <el-pagination @current-change="ChangeCurrent" class="pages" background layout="prev, pager, next" :total="total"></el-pagination>
      </div> -->
    </div>
    <el-dialog :visible.sync="drawer">
      <div class="dialog_div">
        <img src="@/assets/images/shenhe.png" />
        <el-form label-width="60px">
          <el-form-item label="激活码"><el-input type="textarea" :rows="2" style="width: 500px;" placeholder="请输入激活码" v-model="licensetext"></el-input></el-form-item>
        </el-form>
        <el-button @click="active">确定激活</el-button>
      </div>
    </el-dialog>
  </el-container>
</template>

<script>
import {getNewAddonsList, installAddons, uninstallAddons, activeAddons} from '@/api/mall/addons.js';
// import Upload from '@/components/Upload/SingleImage2';

export default {
  data() {
    return {
      list: [],
      total: 1,
      detail: {},
      drawer: false,
      licensetext: ''
    };
  },

  mounted() {
    this.getlist();
  },
  filters: {
    getstatus(data) {
      if (!data.is_active) {
        return '待激活';
      } else {
        if (!data.is_support_install) {
          return '不可安装';
        } else {
          if (data.is_install) {
            return '已安装';
          } else {
            return '待安装';
          }
        }
      }
    }
  },
  methods: {
    getlist() {
      let data = {};
      getNewAddonsList(data).then(res => {
        /*  let data = res.msg; */
        this.list = res.msg;
        this.total = data.total;
      });
    },
    install(id) {
      let _this = this;
      this.$confirm('确认安装插件？')
        .then(_ => {
          let data = {
            addons_id: id
          };
          installAddons(data).then(res => {
            this.getlist();
          });
        })
        .catch(_ => {});
    },
    uninstall(id) {
      let _this = this;
      this.$confirm('确认卸载插件？')
        .then(_ => {
          let data = {
            addons_id: id
          };
          uninstallAddons(data).then(res => {
            _this.getlist();
          });
        })
        .catch(_ => {});
    },
    beforeactive(id) {
      this.id = id;
      this.licensetext = '';
      this.drawer = true;
    },
    active(id) {
      let _this = this;
      this.$confirm('确认激活插件？')
        .then(_ => {
          let data = {
            addons_id: this.id,
            license: _this.licensetext
          };
          activeAddons(data).then(res => {
            _this.drawer=false
            _this.getlist();
          });
        })
        .catch(_ => {});
    },
    SelectHadnle() {},

    getimg(data) {
      this.detail.img = data;
    },
    editsave() {
      editaddons(this.detail).then(res => {
        this.getlist();
        this.drawer = false;
      });
    },
    addaddons() {},
    search() {},
    ChangeCurrent() {}
  }
};
</script>

<style></style>
